//
// Created by ZMX on 2017/10/23.
//

#include "Shape.h"

void Shape_Base::switch90() {
    circle += 90;
}

int Shape_Base::getWidth() {
    int c = circle % 360;
    if (c == 90 || c == 270) {
        return height;
    }
    return width;
}

int Shape_Base::getHeight() {
    int c = circle % 360;
    if (c == 90 || c == 270) {
        return width;
    }
    return height;
}

void LShape::getPosition(set<pair<int, int>> &set) {
    shapeSet.clear();
    switch (circle % 360) {
        case 0: {
            shapeSet.insert(pair<int, int>(0, 0));
            shapeSet.insert(pair<int, int>(0, 1));
            shapeSet.insert(pair<int, int>(0, 2));
            shapeSet.insert(pair<int, int>(1, 0));
            break;
        }
        case 90: {
            shapeSet.insert(pair<int, int>(0, 0));
            shapeSet.insert(pair<int, int>(1, 0));
            shapeSet.insert(pair<int, int>(2, 0));
            shapeSet.insert(pair<int, int>(2, 1));
            break;
        }
        case 180: {
            shapeSet.insert(pair<int, int>(0, 2));
            shapeSet.insert(pair<int, int>(1, 0));
            shapeSet.insert(pair<int, int>(1, 1));
            shapeSet.insert(pair<int, int>(1, 2));
            break;
        }
        case 270: {
            shapeSet.insert(pair<int, int>(0, 0));
            shapeSet.insert(pair<int, int>(0, 1));
            shapeSet.insert(pair<int, int>(1, 1));
            shapeSet.insert(pair<int, int>(2, 1));
            break;
        }
        default: {
            shapeSet.insert(pair<int, int>(0, 0));
            shapeSet.insert(pair<int, int>(0, 1));
            shapeSet.insert(pair<int, int>(0, 2));
            shapeSet.insert(pair<int, int>(1, 0));
            break;
        }
    }

    auto it = shapeSet.begin();
    while (it != shapeSet.end()) {
        pair<int, int> np;
        np.first = it->first;
        np.second = it->second;
        set.insert(np);
        it++;
    }
}

void CShape::getPosition(set<pair<int, int>> &set) {
    auto it = shapeSet.begin();
    while (it != shapeSet.end()) {
        set.insert(*it);
        it++;
    }
}

void SShape::getPosition(set<pair<int, int>> &set) {
    auto it = shapeSet.begin();
    while (it != shapeSet.end()) {
        pair<int, int> np;
        switch (circle % 180) {
            case 0: {
                np.first = it->first;
                np.second = it->second;
                break;
            }
            case 90: {
                np.first = it->second;
                np.second = getHeight() - it->first;
                break;
            }
            default: {
                np.first = it->first;
                np.second = it->second;
                break;
            }
        }

        set.insert(np);
        it++;
    }
}

void IShape::getPosition(set<pair<int, int>> &set) {
    shapeSet.clear();
    switch (circle % 180) {
        case 0: {
            shapeSet.insert(pair<int, int>(0, 0));
            shapeSet.insert(pair<int, int>(0, 1));
            shapeSet.insert(pair<int, int>(0, 2));
            shapeSet.insert(pair<int, int>(0, 3));
            break;
        }
        case 90: {
            shapeSet.insert(pair<int, int>(0, 0));
            shapeSet.insert(pair<int, int>(1, 0));
            shapeSet.insert(pair<int, int>(2, 0));
            shapeSet.insert(pair<int, int>(3, 0));
            break;
        }
        default: {
            shapeSet.insert(pair<int, int>(0, 0));
            shapeSet.insert(pair<int, int>(0, 1));
            shapeSet.insert(pair<int, int>(0, 2));
            shapeSet.insert(pair<int, int>(0, 3));
            break;
        }
    }

    auto it = shapeSet.begin();
    while (it != shapeSet.end()) {
        pair<int, int> np;
        np.first = it->first;
        np.second = it->second;
        set.insert(np);
        it++;
    }
}
